using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class UIEvent : MonoBehaviour
{
    public GameObject brid;

    public List<GameObject> prefabs;

    private int birdIndex=0;

    private GameObject birdObject;
    
    // Start is called before the first frame update
    void Start()
    {
        InitBird();
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    public void PlayGame()
    {
        birdObject.GetComponent<BridMove>().ifLeave=true;
        PlayerPrefs.SetInt("birdID",birdIndex);
        Invoke(nameof(BeginPlayGame), 1);
    }

    public void LastBird()
    {
        if(birdIndex==0)
        {
            birdIndex=prefabs.Count-1;
        }
        else
        {
            birdIndex--;
        }
        InitBird();
    }
    public void NextBird()
    {
        if(birdIndex==prefabs.Count-1)
        {
            birdIndex=0;
        }
        else
        {
            birdIndex++;  
        }
        InitBird();
    }

    public void ExitGame()
    {
        Application.Quit();
    }
    private void InitBird()
    {
        if(birdObject)
        {
            birdObject.GetComponent<BridMove>().ifLeave=true;
        }
        birdObject=Instantiate(prefabs[birdIndex]);
        birdObject.transform.position=new Vector2(0,0);
        birdObject.transform.parent=brid.transform;
        
    }
    private void BeginPlayGame()
    {
        SceneManager.LoadScene("PlayGame");
    }
}
